/**
 * @author mikael emtinger / http://gomo.se/
 */

GLE.Sprite = function ( parameters ) {

	GLE.Object3D.call( this );

	this.color = ( parameters.color !== undefined ) ? new GLE.Color( parameters.color ) : new GLE.Color( 0xffffff );
	this.map = ( parameters.map !== undefined ) ? parameters.map : new GLE.Texture();
	this.blending = ( parameters.blending !== undefined ) ? parameters.blending : GLE.NormalBlending;

	this.useScreenCoordinates = ( parameters.useScreenCoordinates !== undefined ) ? parameters.useScreenCoordinates : true;
	this.mergeWith3D = ( parameters.mergeWith3D !== undefined ) ? parameters.mergeWith3D : !this.useScreenCoordinates;
	this.affectedByDistance = ( parameters.affectedByDistance !== undefined ) ? parameters.affectedByDistance : !this.useScreenCoordinates;
	this.scaleByViewport = ( parameters.scaleByViewport !== undefined ) ? parameters.scaleByViewport : !this.affectedByDistance;
	this.alignment = ( parameters.alignment instanceof GLE.Vector2 ) ? parameters.alignment : GLE.SpriteAlignment.center;

	this.rotation3d = this.rotation;
	this.rotation = 0;
	this.opacity = 1;

	this.uvOffset = new GLE.Vector2( 0, 0 );
	this.uvScale  = new GLE.Vector2( 1, 1 );

};

GLE.Sprite.prototype = new GLE.Object3D();
GLE.Sprite.prototype.constructor = GLE.Sprite;


/*
 * Custom update matrix
 */

GLE.Sprite.prototype.updateMatrix = function () {

	this.matrix.setPosition( this.position );

	this.rotation3d.set( 0, 0, this.rotation );
	this.matrix.setRotationFromEuler( this.rotation3d );

	if ( this.scale.x !== 1 || this.scale.y !== 1 ) {

		this.matrix.scale( this.scale );
		this.boundRadiusScale = Math.max( this.scale.x, this.scale.y );

	}

	this.matrixWorldNeedsUpdate = true;

};

/*
 * Alignment
 */

GLE.SpriteAlignment = {};
GLE.SpriteAlignment.topLeft = new GLE.Vector2( 1, -1 );
GLE.SpriteAlignment.topCenter = new GLE.Vector2( 0, -1 );
GLE.SpriteAlignment.topRight = new GLE.Vector2( -1, -1 );
GLE.SpriteAlignment.centerLeft = new GLE.Vector2( 1, 0 );
GLE.SpriteAlignment.center = new GLE.Vector2( 0, 0 );
GLE.SpriteAlignment.centerRight = new GLE.Vector2( -1, 0 );
GLE.SpriteAlignment.bottomLeft = new GLE.Vector2( 1, 1 );
GLE.SpriteAlignment.bottomCenter = new GLE.Vector2( 0, 1 );
GLE.SpriteAlignment.bottomRight = new GLE.Vector2( -1, 1 );
